#include <text_code.h>

char* utf8togb2312(String input_data)
{
  int input_num = input_data.length();
  int output_num = 0;
  unsigned char str[input_num];
  byte select = 0;
  for (int x = 0; x < input_num; x++)
  {
    str[x] = input_data.charAt(x);
    select = Transform.GetUtf8ByteNumForWord(str[x]);
    if (select == 0)
      output_num++;
    else if (select >= 2)
      output_num += 2;
  }
  uint8_t gbArray[output_num];
  Transform.Utf8ToGb2312(str, input_num, gbArray);
  char gbArray1[output_num];
  static String data;
  data = "";
  for (int x = 0; x < output_num; x++)
  {
    data = String(data) + String(char(gbArray[x]));
  }
  char* gbkstr = const_cast<char*>(data.c_str());
  return gbkstr;
}

void TTS(String data) {
  Serial.println(data);
  data = utf8togb2312(data);
  int data_length = String(data).length() + 2;
  Serial2.write(0xfd);
  Serial2.write((data_length >> 8) & 0xFF);
  Serial2.write(data_length & 0xFF);
  Serial2.write(0x01);
  Serial2.write(0x01);
  Serial2.write(data.c_str());
}